home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / FastFixedPoint.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  3.2 KB  |  73 lines  |  [TEXT/KAHL]

  1. /* FastFixedPoint.h */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #ifndef Included_FastFixedPoint_h
  26. #define Included_FastFixedPoint_h
  27.  
  28. /* FastFixedPoint module depends on */
  29. /* MiscInfo.h */
  30. /* Audit */
  31. /* Debug */
  32. /* Definitions */
  33.  
  34. #define FASTFIXEDPRECISION (15)
  35.  
  36. typedef signed long FastFixedType;
  37.  
  38. #define FASTFIXEDFRACTMASK ((((FastFixedType)1L) << FASTFIXEDPRECISION) - 1)
  39.  
  40. #define FastFixedTimes16BitTo16Bit(fastfixed,sixteenbit) (((fastfixed)\
  41.                     * (sixteenbit)) >> (FASTFIXEDPRECISION))
  42.  
  43. #define FastFixedTimes8BitTo16Bit(fastfixed,eightbit) (((fastfixed)\
  44.                     * (eightbit)) >> (-(16 - (FASTFIXEDPRECISION + 8))))
  45.  
  46. #define FastFixedTimes16BitTo24Bit(fastfixed,sixteenbit) (((fastfixed)\
  47.                     * (sixteenbit)) >> (-(24 - (FASTFIXEDPRECISION + 16))))
  48.  
  49. #define FastFixedTimes8BitTo24Bit(fastfixed,eightbit) (((fastfixed) * (eightbit))\
  50.                     << (24 - (FASTFIXEDPRECISION + 8)))
  51.  
  52. #define FastFixedTimes8BitToFastFixed(fastfixed,eightbit) (((fastfixed)\
  53.                     * (eightbit)) >> 8)
  54.  
  55. #define FastFixedTimes16BitToFastFixed(fastfixed,sixteenbit) (((fastfixed)\
  56.                     * (sixteenbit)) >> 16)
  57.  
  58. #define FastFixedTimesFastFixedToFastFixed(left,right) (((left)\
  59.                     * (right)) >> FASTFIXEDPRECISION)
  60.  
  61. #define Double2FastFixed(x) ((signed long)((x) * (1L << FASTFIXEDPRECISION)\
  62.                     + ((x >= 0) ? 0.5 : -0.5)))
  63.  
  64. #define FastFixed2Double(x) (((double)(x)) / (1L << FASTFIXEDPRECISION))
  65.  
  66. #define FastFixed2Float(x) (((float)(x)) / (1L << FASTFIXEDPRECISION))
  67.  
  68. #define Int2FastFixed(x) ((signed long)(x) << FASTFIXEDPRECISION)
  69.  
  70. #define FastFixed2Int(x) ((signed long)(x) >> FASTFIXEDPRECISION)
  71.  
  72. #endif
  73.